import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
// import componentsRouter from './modules/components'
// import chartsRouter from './modules/charts'
// import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'
import memberRouter from './modules/member'
import venueRouter from './modules/venue'
import shareholderRouter from './modules/shareholder'
import courseRouter from './modules/course' // 课程管理
import contractRouter from './modules/contract' // 电子合同
import informationRouter from './modules/information' // 数据分析
import financeRouter from './modules/finance' // 财务报表
import systemRouter from './modules/system' // 系统设置
import smsRouter from './modules/sms' // 短信管理
import diagnosisRouter from './modules/diagnosis' // 场所经营诊断

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
 roles: ['admin','editor']    control the page roles (you can set multiple roles)
 title: 'title'               the name show in sidebar and breadcrumb (recommend set)
 icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
 noCache: true                if set true, the page will no be cached(default is false)
 affix: true                  if set true, the tag will affix in the tags-view
 breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
 activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
 }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
  path: '/redirect',
  component: Layout,
  hidden: true,
  children: [{
    path: '/redirect/:path(.*)',
    component: () => import('@/views/redirect/index')
  }]
},
{
  path: '/login',
  component: () => import('@/views/login/index'),
  hidden: true
},

{
  path: '/retakePassword',
  component: () => import('@/views/login/retakePassword'),
  hidden: true
},
{
  path: '/register',
  component: () => import('@/views/login/register'),
  hidden: true
},
{
  path: '/switchVenue',
  component: () => import('@/views/login/switchVenue'),
  hidden: true
},
{
  path: '/auth-redirect',
  component: () => import('@/views/login/auth-redirect'),
  hidden: true
},
{
  path: '/404',
  component: () => import('@/views/error-page/404'),
  hidden: true
},
{
  path: '/401',
  component: () => import('@/views/error-page/401'),
  hidden: true
},
{
  path: '/',
  component: Layout,
  redirect: '/dashboard',
  children: [{
    path: 'dashboard',
    component: () => import('@/views/dashboard/index'),
    name: 'Dashboard',
    meta: {
      title: 'dashboard',
      icon: 'dashboard',
      affix: true
    }
  }, {
    path: 'privateappointment',
    component: () => import('@/views/dashboard/privateappointment'),
    name: 'privateappointment',
    hidden: true,
    meta: {
      title: 'dashboard',
      icon: 'dashboard',
      activeMenu: '/dashboard'
    }
  }, {
    path: 'changePassword',
    component: () => import('@/views/login/changePassword'),
    name: 'changePassword',
    hidden: true,
    meta: {
      title: '修改密码'
    }
  }, {
    path: 'punishment',
    component: () => import('@/views/dashboard/punishment'),
    name: 'punishment',
    hidden: true,
    meta: {
      title: 'dashboard',
      icon: 'dashboard',
      activeMenu: '/dashboard'
    }
  }, {
    path: 'leavemanage',
    component: () => import('@/views/dashboard/leavemanage'),
    name: 'leavemanage',
    hidden: true,
    meta: {
      title: 'dashboard',
      icon: 'dashboard',
      activeMenu: '/dashboard'
    }
  }, {
    path: 'classrecord',
    component: () => import('@/views/dashboard/classrecord'),
    name: 'classrecord',
    hidden: true,
    meta: {
      title: 'dashboard',
      icon: 'dashboard',
      activeMenu: '/dashboard'
    }
  }, {
    path: 'locker',
    component: () => import('@/views/dashboard/locker'),
    name: 'locker',
    hidden: true,
    meta: {
      title: 'dashboard',
      icon: 'dashboard',
      activeMenu: '/dashboard'
    }
  },

  {
    path: 'help',
    component: () => import('@/views/dashboard/help'),
    name: 'help',
    hidden: true,
    meta: {
      title: 'help'
    }
  },
  {
    path: 'exportCenter',
    component: () => import('@/views/dashboard/exportCenter'),
    name: 'exportCenter',
    hidden: true,
    meta: {
      title: '工作台'
    }
  }
  ]
},
{
  path: '/workbenchRemind',
  component: Layout,
  children: [{
    path: 'workbenchRemind',
    component: () => import('@/views/workbenchRemind/index'),
    name: 'workbenchRemind',
    meta: {
      title: '今日消息提醒',
      icon: 'documentation',
      affix: true
    }
  }]
},
{
  path: '/brandManage2',
  component: Layout,
  children: [{
    path: 'brandManage2',
    component: () => import('@/views/brandManage/brandManage'),
    name: 'brandManage2',
    meta: {
      title: '品牌设置',
      icon: 'brand',
      affix: true
    }
  }]
},
{
  path: '/memberlist2',
  component: Layout,
  children: [{
    path: 'memberlist2',
    component: () => import('@/views/member/memberlist2'),
    name: 'memberlist2',
    meta: {
      title: '会员列表',
      icon: 'brand',
      affix: true
    }
  }]
},
// {
// 	path: '/journal',
// 	component: Layout,
// 	children: [{
// 		path: 'journal',
// 		component: () => import('@/views/brandManage/brandManage'),
// 		name: 'journal',
// 		meta: {
// 			title: '操作日志',
// 			icon: 'brand',
// 			affix: true
// 		}
// 	}]
// },
{
  path: '/liansuo',
  component: Layout,
  name: 'liansuo',
  meta: {
    title: '连锁管理',
    icon: 'liansuo'
  },
  children: [
    {
      path: 'currencycard',
      component: () => import('@/views/member/currencycard'),
      name: 'currencycard',
      meta: {
        title: '通用卡种类'
      }
    },
    {
      path: 'integralset',
      component: () => import('@/views/member/integralset'),
      name: 'integralset',
      meta: {
        title: '积分设置'
      }
    }, {
      path: 'integralsetedit',
      component: () => import('@/views/member/integralsetedit'),
      name: 'integralsetedit',
      hidden: true,
      meta: {
        title: '积分设置'
      }
    }, {
      path: 'userauth',
      component: () => import('@/views/member/userauth'),
      name: 'userauth',
      hidden: false,
      meta: {
        title: '角色权限'
      }
    }, {
      path: 'userauthedit',
      component: () => import('@/views/member/userauthedit'),
      name: 'userauthedit',
      hidden: false,
      meta: {
        title: '新增角色'
      }
    }
    // {
    // 	path: 'liansuo2',
    // 	component: () => import('@/views/workbenchRemind/index'),
    // 	name: 'liansuo2',
    // 	meta: {
    // 		title: '权限设置'
    // 	}
    // }
  ]
},
{
  path: '/sms2',
  component: Layout,
  name: 'sms2',
  meta: {
    title: '短信管理',
    icon: 'brand'
  },
  children: [{
    path: 'smsTopUp2',
    component: () => import('@/views/sms2/smsTopUp'),
    name: 'smsTopUp2',
    meta: {
      title: '充值短信',
      icon: 'brand',
      affix: true
    }
  }, {
    path: 'distribute',
    component: () => import('@/views/sms2/distribute'),
    name: 'distribute',
    meta: {
      title: '分发短信',
      icon: 'brand',
      affix: true
    }
  }, {
    path: 'smsSendRecord2',
    component: () => import('@/views/sms2/smsSendRecord'),
    name: 'smsSendRecord2',
    meta: {
      title: '短信发送记录',
      icon: 'brand',
      affix: true
    }
  }, {
    path: 'distributeLog',
    component: () => import('@/views/sms2/distributeLog'),
    name: 'distributeLog',
    hidden: true,
    meta: {
      title: '修改密码'
    }
  }, {
    path: 'smsBuy',
    component: () => import('@/views/sms2/smsBuy'),
    name: 'smsBuy',
    hidden: true,
    meta: {
      title: '充值短信'
    }
  }]
},
// {
// 	path: '/Finance',
// 	component: Layout,
// 	name: 'Finance',
// 	meta: {
// 		title: '财务统计',
// 		icon: 'caiwu'
// 	},
// 	children: [{
// 		path: 'Finance',
// 		component: () => import('@/views/workbenchRemind/index'),
// 		name: 'Finance',
// 		meta: {
// 			title: '通用卡种类'
// 		}
// 	}, {
// 		path: 'Finance',
// 		component: () => import('@/views/workbenchRemind/index'),
// 		name: 'Finance',
// 		meta: {
// 			title: '积分设置'
// 		}
// 	}, {
// 		path: 'Finance',
// 		component: () => import('@/views/workbenchRemind/index'),
// 		name: 'Finance',
// 		meta: {
// 			title: '权限设置'
// 		}
// 	}]
// },

memberRouter, // 会员管理
courseRouter, // 课程管理
venueRouter, // 场馆管理
shareholderRouter, // 共享股东
contractRouter, // 电子合同
informationRouter, // 数据分析
financeRouter, // 财务报表
systemRouter, // 系统设置
smsRouter, // 短信管理
diagnosisRouter, // 场所经营诊断
{
  path: '/normalMini',
  component: Layout,
  children: [{
    path: 'index',
    component: () => import('@/views/normalMini/index'),
    name: 'normalMini',
    meta: {
      title: '约课助手小程序',
      icon: 'normalMini',
      affix: true
    }
  }]
}, {
  path: '/AlipayDivide',
  component: Layout,
  children: [{
    path: 'AlipayDivide',
    component: () => import('@/views/AlipayDivide/index'),
    name: 'AlipayDivide',
    meta: {
      title: '支付宝分期付',
      icon: 'normalMini',
      affix: true
    }
  }]
}
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [

  // 404 page must be placed at the end !!!
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
